package br.com.marcelo.reservasis.client.pagina.login;

import br.com.aroeirasoftware.gwtcomponents.client.components.ASApplication;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASButton;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASField;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASOrientation;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASPage;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASPanel;
import br.com.aroeirasoftware.gwtcomponents.client.components.ASTextBox;
import br.com.aroeirasoftware.gwtcomponents.client.i18n.ASGWTComponentsI18N;
import br.com.marcelo.reservasis.client.componentes.ReservaSISApplication;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.PasswordTextBox;

/**
 *
 * @author Marcelo
 */
public class LoginPagina extends ASPage {

    private ASPanel painel;
    private ASField campoUsuario;
    private ASField campoSenha;
    private ASOrientation orientacao;
    private ASButton bLogin;

    public LoginPagina(ASPage paginaAnterior, ASApplication aplicacao, ASOrientation orientacao) {
        super(paginaAnterior, aplicacao,
                ASGWTComponentsI18N.messages.tituloPaginaLogin(),
                "");
        this.orientacao = orientacao;

        configurarComponentes();
    }

    @Override
    public void configurarDados() {
    }

    @Override
    public void configurarComponentes() {
        campoUsuario = new ASField("usuario", ASGWTComponentsI18N.messages.geralUsuario(),
                String.class, String.class, new ASTextBox(), orientacao);
        campoSenha = new ASField("senha", ASGWTComponentsI18N.messages.geralSenha(),
                String.class, String.class, new PasswordTextBox(), orientacao);

        bLogin = new ASButton(ASGWTComponentsI18N.messages.btnAcessar(), new ClickHandler() {

            public void onClick(ClickEvent event) {
                ReservaSISApplication.getInstance().login(campoUsuario.getValue());
            }
        });
        bLogin.addEstiloDefault();

        painel = new ASPanel();
        painel.setTitulo(ASGWTComponentsI18N.messages.tituloPaginaLogin());
        painel.add(campoUsuario, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
        painel.add(campoSenha, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
        painel.setRodape(bLogin);
        painel.setRodapeHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        painel.setWidth("300px");

        add(painel, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);

        campoUsuario.setFocus();
    }

    @Override
    public void abrir() {
    }
}
